<?php

namespace app\admin\model\giy;

use think\Model;


class Order extends Model
{

    

    

    // 表名
    protected $table = 'gjy_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'pay_type_text',
        'goods_type_text',
        'order_status_text'
    ];
    

    
    public function getPayTypeList()
    {
        return ['1' => __('Pay_type 1'), '2' => __('Pay_type 2')];
    }

    public function getGoodsTypeList()
    {
        return ['1' => __('Goods_type 1'), '2' => __('Goods_type 2'), '3' => __('Goods_type 3')];
    }

    public function getOrderStatusList()
    {
        return ['1' => __('Order_status 1'), '2' => __('Order_status 2'), '3' => __('Order_status 3'), '5' => __('Order_status 5'), '6' => __('Order_status 6')];
    }


    public function getPayTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
        $list = $this->getPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGoodsTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['goods_type']) ? $data['goods_type'] : '');
        $list = $this->getGoodsTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOrderStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function goods()
    {
        return $this->belongsTo('app\admin\model\Goods', 'goods_id', 'goods_id', [], 'LEFT')->setEagerlyType(0);
    }


    public function address()
    {
        return $this->belongsTo('app\admin\model\user\Address', 'address_id', 'address_id', [], 'LEFT')->setEagerlyType(0);
    }

}
